package com.zecan.blog.controller.exception.handler;

import com.zecan.blog.common.BlogResult;
import com.zecan.blog.controller.exception.*;
import com.zecan.blog.utils.BlogResultUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.IOException;

/**
 * @ClassName BlogExceptionHandler
 * @Description
 * @date 2022/11/2 17:43
 * @Version 1.0
 */
@RestControllerAdvice("com.zecan.blog.controller")
public class BlogExceptionHandler {
    private static final Logger logger = LoggerFactory.getLogger(BlogExceptionHandler.class);

    @ExceptionHandler(UserException.class)
    public BlogResult userExceptionHandle(UserException e) throws IOException {
        logger.error("UserException: --> " + e.getMessage());
       return BlogResultUtils.exception(e);
    }

    @ExceptionHandler(BlogException.class)
    public BlogResult blogExceptionHandler(BlogException e) throws IOException {
        logger.error("BlogException: --> " + e.getMessage());
        return BlogResultUtils.exception(e);
    }

    @ExceptionHandler(CommentException.class)
    public BlogResult commentExceptionHandler(CommentException e) throws IOException {
        logger.error("CommentException: --> " + e.getMessage());
        return BlogResultUtils.exception(e);
    }

    @ExceptionHandler(ClassifyException.class)
    public BlogResult classifyExceptionHandler(ClassifyException e) throws IOException {
        logger.error("ClassifyException: --> " + e.getMessage());
        return BlogResultUtils.exception(e);
    }

    @ExceptionHandler(TagException.class)
    public BlogResult tagExceptionHandler(TagException e) throws IOException {
        logger.error("ClassifyException: --> " + e.getMessage());
        return BlogResultUtils.exception(e);
    }


    @ExceptionHandler(StarGoodException.class)
    public BlogResult starGoodExceptionHandler(StarGoodException e) throws IOException {
        logger.error("StarGoodException: --> " + e.getMessage());
        return BlogResultUtils.exception(e);
    }
}
